// @ts-ignore
/* eslint-disable */
import { requestAuth } from '@/utils/request';

/** 获取角色列表 */
export async function fetchRoleData(data: {
  current: number;
  size: number;
  params: {
    column: string;
    type: string;
    values?: string;
  }[];
}) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/page',
    data,
  });
}

/** 检查角色编码是否重复 */
export async function checkRoleCode(data: { id?: string; roleKey: string }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/check',
    data,
    skipErrorHandler: true, // 不展示接口请求的通用异常处理提示
  });
}

/** 角色新增 */
export async function addRole(data: {
  roleKey: string;
  roleName: string;
  roleType: string;
  roleStatus: string;
}) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/save',
    data,
  });
}

/** 角色修改 */
export async function modifyRole(data: {
  id: string;
  roleKey: string;
  roleName: string;
  roleType: string;
  roleStatus: string;
}) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/update',
    data,
  });
}

/** 角色删除 */
export async function deleteRoleById(data: { id: string }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/delete',
    data,
  });
}

/** 角色批量删除 */
export async function batchDeleteRoleByIds(data: { ids: string[] }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/deleteBatch',
    data,
  });
}

/** 获取角色已授权的菜单资源 */
export async function fetchResourceAuthByRoleId(data: { roleId: string }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resource/getResourceIdListByRoleId',
    data,
  });
}

/** 更新角色授权的菜单资源 */
export async function updateResourceAuthByRoleId(data: { roleId: string; resIds: string[] }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/saveAuthResource',
    data,
  });
}

/** 获取角色菜单资源下授权的按钮列表 */
export async function fetchResourceButtonAuthByRoleId(data: {
  roleId: string;
  resourceId: string;
}) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/getResourceComponentListByRoleId',
    data,
  });
}

/** 更新角色菜单资源下授权的按钮列表 */
export async function updateResourceButtonAuthByRoleId(data: {
  roleId: string;
  resourceId: string;
  resIds: string[];
}) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/saveAuthComponentResource',
    data,
  });
}

/** 查询角色关联的机构列表 */
export async function fetchRoleDepartmentRelation(data: { roleId: string }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/roleOrganList',
    data,
  });
}

/** 更新角色关联机构 */
export async function updateRoleDepartmentRelation(data: { roleId: string; organList: string[] }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/role/bindOrganList',
    data,
  });
}
